"""
date:2019/5/27
配置文件里不要包含特殊符号：%,\
"""
from telnetlib import Telnet
import re


class MyTelnet(Telnet):
    def __init__(self, host_, port_, user, passwd):
        super().__init__(host_, port_)
        # self.write(b' \n')
        self.write(user.encode())
        self.write(b'\n')
        self.write(passwd.encode())
        self.write(b'\n')
        self.expect([b'<.+>'])
        self.write(b'dis cu\n')

    def fill_rawq(self):
        if self.irawq >= len(self.rawq):
            self.rawq = b''
            self.irawq = 0
        buf = self.sock.recv(1000)      # 对接收的数据容量扩大，以避免一行不能完整的输出。
        self.msg("recv %r", buf)
        self.eof = (not buf)
        self.rawq = self.rawq + buf



t = Telnet(host='172.23.1.20', port='22')
t.write(b'zhang\n')
t.write(b'zhangchen@123\n')
while 1:
    print(t.read_some())


